package com.ciwong.epaper.modules.me.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.epaper.util.EpaperJumpManager;
import com.ciwong.epaper.modules.homework.bean.PublishWorkRecords;
import com.ciwong.epaper.modules.me.bean.HomeWorkContents;
import com.ciwong.mobilelib.i.ViewOnClickListener;

import java.util.List;

/**
 * @description:
 * @author: wyk
 * @time: 2021/6/24 11:34
 */
public class AttentionWorkChildAdapter extends BaseAdapter {
    private List<HomeWorkContents> workContents;
    private Context mContext;
    private int studentCount;
    private PublishWorkRecords publishWorkRecords;

    public AttentionWorkChildAdapter(Context mContext, List<HomeWorkContents> workContents, int studentCount, PublishWorkRecords publishWorkRecords){
        this.mContext = mContext;
        this.workContents = workContents;
        this.studentCount = studentCount;
        this.publishWorkRecords = publishWorkRecords;
    }

    @Override
    public int getCount() {
        return workContents.size();
    }

    @Override
    public Object getItem(int i) {
        return workContents.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        viewHelper viewHelper = null;
        if (null == view){
            viewHelper = new viewHelper();
            view = LayoutInflater.from(mContext).inflate(R.layout.activity_attention_work_item, null);
            viewHelper.work_finish_count = (TextView) view.findViewById(R.id.work_finish_count);
            viewHelper.work_resourceName = (TextView) view.findViewById(R.id.work_resourceName);
            viewHelper.work_name_lay = (RelativeLayout) view.findViewById(R.id.work_name_lay);
            viewHelper.tea_work_line = (View) view.findViewById(R.id.tea_work_line);
            view.setTag(viewHelper);
        }else {
            viewHelper = (viewHelper)view.getTag();
        }
        HomeWorkContents homeWorkContents = workContents.get(i);
        viewHelper.work_resourceName.setText(homeWorkContents.getResourceName());
        viewHelper.work_finish_count.setText(homeWorkContents.getFinishCount()+"/"+studentCount);
        if (i == workContents.size()-1){
            viewHelper.tea_work_line.setVisibility(View.GONE);
        }
        viewHelper.work_name_lay.setOnClickListener(new ViewOnClickListener() {
            @Override
            public void avertRepeatOnClick(View view) {
                EpaperJumpManager.jumpToStudentGrades((Activity) mContext,publishWorkRecords,i,workContents.get(i),R.id.go_back);
            }
        });
        return view;
    }

    private class viewHelper{
        private TextView work_resourceName;

        private TextView work_finish_count;

        private RelativeLayout work_name_lay;

        private View tea_work_line;


    }
}
